package org.example.ims.Repository.Base;

import org.example.ims.Entity.Base.Product;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

public interface ProductRepository extends JpaRepository<Product, Integer> {
    @Query("SELECT p FROM Product p " +
            "WHERE (:name IS NULL OR p.productName = :name)" +
            "AND (:categoryId IS NULL OR p.category.categoryId = :categoryId) " +
            "AND (:status IS NULL OR p.productStatus = :status)")
    Page<Product> searchProducts(@Param("name") String name,
                               @Param("categoryId") Integer categoryId,
                               @Param("status") String status,
                               Pageable pageable);
}
